<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>sfload</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="sfinstrm.html" title="sfinstrm" />
    <link rel="next" href="sflooper.html" title="sflooper" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">sfload</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="sfinstrm.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="sflooper.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="sfload"></a>
      <div class="titlepage"></div>
      <a id="IndexSfload" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">sfload</span>
        </h2>
        <p>sfload — 
      Loads an entire SoundFont2 (SF2) sample file into memory.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp146280640"></a>
        <h2>Description</h2>
        <p>
      Loads an entire SoundFont2 (SF2) sample file into memory. These opcodes allow management the sample-structure of SF2 files. In order to understand the usage of these opcodes, the user must have some knowledge of the SF2 format, so a brief description of this format can be found in the <a class="link" href="MiscSf2.html" title="Appendix G. SoundFont2 File Format"><em class="citetitle">SoundFont2 File Format Appendix</em></a>.
    </p>
        <p>
      <span class="emphasis"><em>sfload</em></span> should be placed in the header section of a Csound orchestra.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp146326672"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ir <span class="command"><strong>sfload</strong></span> "filename"</pre>
      </div>
      <div class="refsect1">
        <a id="idp146328864"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ir</em></span> -- output to be used by other SF2 opcodes. For <span class="emphasis"><em>sfload</em></span>, <span class="emphasis"><em>ir</em></span> is <span class="emphasis"><em>ifilhandle</em></span>. 
    </p>
        <p>
      <span class="emphasis"><em><span class="quote">“<span class="quote">filename</span>”</span></em></span> -- name of the SF2
                                file, with its complete path. It must
                                be a string typed within
                                double-quotes with <span class="quote">“<span class="quote">/</span>”</span> to
                                separate directories (this applies to
                                DOS and Windows as well, where using a
                                backslash will generate an error), or
                                an integer that has been the subject
                                of a <a class="link" href="strset.html" title="strset"><em class="citetitle">strset</em></a> operation
    </p>
      </div>
      <div class="refsect1">
        <a id="idp146334592"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>sfload</em></span> loads an entire SF2 file into memory. It returns a file handle to be used by other opcodes. Several instances of <span class="emphasis"><em>sfload</em></span> can placed in the header section of an orchestra, allowing use of more than one SF2 file in a single orchestra.
    </p>
        <p>
      These opcodes only support the sample structure of SF2 files. The modulator structure of the SoundFont2 format is not supported in Csound. Any modulation or processing to the sample data is left to the Csound user, bypassing all restrictions forced by the SF2 standard.
    </p>
        <p>
      It should be noted that before version 5.12 a maximum of 10
      sound fonts could be loaded, a restriction since relaxed.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp146338080"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the sfload opcode. It uses the file <a class="ulink" href="examples/sfload.csd" target="_top"><em class="citetitle">sfload.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp146339936"></a>
          <p class="title">
            <strong>Example 807. Example of the sfload opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac -+rtmidi=virtual -M0   <span class="comment">;;;realtime audio out, virtual midi in</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o sfload.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="comment">;load two soundfonts</span>
isf	<span class="opc">sfload</span>	"07AcousticGuitar.sf2"
ir	<span class="opc">sfload</span>	"01hpschd.sf2"
	<span class="opc">sfplist</span> isf
	<span class="opc">sfplist</span> ir
	<span class="opc">sfpassign</span>	0, isf	
	<span class="opc">sfpassign</span>	1, ir

<span class="oblock">instr</span> 1	<span class="comment">; play guitar from score and midi keyboard - preset index = 0</span>

	<span class="opc">mididefault</span>	60, p3
	<span class="opc">midinoteonkey</span>	p4, p5
inum	<span class="opc">init</span>	p4
ivel	<span class="opc">init</span>	p5
ivel	<span class="opc">init</span>	ivel<span class="op">/</span>127					<span class="comment">;make velocity dependent</span>
kamp	<span class="opc">linsegr</span>	1, 1, 1, .1, 0
kamp	<span class="op">=</span> kamp<span class="op">/</span>3000						<span class="comment">;scale amplitude</span>
kfreq	<span class="opc">init</span>	1						<span class="comment">;do not change freq from sf</span>
a1,a2	<span class="opc">sfplay3</span>	ivel, inum, kamp<span class="op">*</span>ivel, kfreq, 0			<span class="comment">;preset index = 0</span>
	<span class="opc">outs</span>	a1, a2
	
	<span class="oblock">endin</span>
	
<span class="oblock">instr</span> 2	<span class="comment">; play harpsichord from score and midi keyboard - preset index = 1</span>

	<span class="opc">mididefault</span>	60, p3
	<span class="opc">midinoteonkey</span>	p4, p5
inum	<span class="opc">init</span>	p4
ivel	<span class="opc">init</span>	p5
ivel	<span class="opc">init</span>	ivel<span class="op">/</span>127					<span class="comment">;make velocity dependent</span>
kamp	<span class="opc">linsegr</span>	1, 1, 1, .1, 0
kamp	<span class="op">=</span> kamp<span class="op">/</span>1000						<span class="comment">;scale amplitude</span>
kfreq	<span class="opc">init</span>	1						<span class="comment">;do not change freq from sf</span>
a1,a2	<span class="opc">sfplay3</span>	ivel, inum, kamp<span class="op">*</span>ivel, kfreq, 1			<span class="comment">;preset index = 1</span>
	<span class="opc">outs</span>	a1, a2
	
<span class="oblock">endin</span>
	
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>0  60				<span class="comment">; stay active for 1 minute</span>

<span class="stamnt">i</span>1 0 1 60 100
<span class="stamnt">i</span>1 + 1 62 &lt;
<span class="stamnt">i</span>1 + 1 65 &lt;
<span class="stamnt">i</span>1 + 1 69 10

<span class="stamnt">i</span>2 5 1 60 100
<span class="stamnt">i</span>2 + 1 62 &lt;
<span class="stamnt">i</span>2 7 1 65 &lt;
<span class="stamnt">i</span>2 7 1 69 10

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp146344224"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="sfilist.html" title="sfilist"><em class="citetitle">sfilist</em></a>,
      <a class="link" href="sfinstr.html" title="sfinstr"><em class="citetitle">sfinstr</em></a>,
      <a class="link" href="sfinstrm.html" title="sfinstrm"><em class="citetitle">sfinstrm</em></a>,
      <a class="link" href="sfpassign.html" title="sfpassign"><em class="citetitle">sfpassign</em></a>,
      <a class="link" href="sfplay.html" title="sfplay"><em class="citetitle">sfplay</em></a>,
      <a class="link" href="sfplaym.html" title="sfplaym"><em class="citetitle">sfplaym</em></a>,
      <a class="link" href="sfplist.html" title="sfplist"><em class="citetitle">sfplist</em></a>,
      <a class="link" href="sfpreset.html" title="sfpreset"><em class="citetitle">sfpreset</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp146352992"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Gabriel Maldonado</td>
          </tr>
          <tr>
            <td>Italy</td>
          </tr>
          <tr>
            <td>May 2000</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound Version 4.07</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="sfinstrm.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="sflooper.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">sfinstrm </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> sflooper</td>
        </tr>
      </table>
    </div>
  </body>
</html>
